var qian = ['a' ,'c' ,'f' ,'g' ,'b' ,'d' ,'e'];
var zhong = ['f' ,'c' ,'g' ,'a' ,'b' ,'d' ,'e'];
function Node(value){
    this.value = value;
    this.left = null;
    this.right = null;
}

function fn(qian ,zhong) {
    if(qian == null|| zhong == null || qian.length==0 || zhong.length==0 ) return null;
    var root  = new Node(qian[0]);
    var index = zhong.indexOf(root.value);
    var qianLeft = qian.slice(1, 1 + index);
    var qianRight = qian.slice(index + 1, qian.length);
    var zhongLeft = zhong.slice(0 , index);
    var zhongRight = zhong.slice(index + 1 ,zhong.length);
    root.left = fn(qianLeft,zhongLeft);
    root.right = fn(qianRight,zhongRight);
    return root;
}

var root = fn(qian,zhong);
console.log(root.left);
console.log(root.right);